<template>
	<view class="leave">
		<view @click="clickMore" class="check-more-btn">
			<view class="more-line"></view>
			<text>申请记录</text>
		</view>
		<view class="show-days">
			<view class="days-box1">
				<view class="box-days-num">{{ leaveDays.onVacation }}</view>
				<view class="days-tips">已休天数</view>
			</view>
			<view class="days-box2">
				<view class="box-days-num">{{ leaveDays.vacationUsed }}</view>
				<view class="days-tips">剩余天数</view>
			</view>
		</view>
		<view class="leave-inform-list">
			<view class="leave-wrap">
				<!-- <my-list
					propTitle="所在科室"
					propValue="分泌科"
					boldValue
					valueColor='#121F2C'
					:boder="false"
				></my-list> -->
				<picker :value="workPeriodValue" @change="workPeriodSelect" class="picker-view" :range="worKPeriodOption" range-key="yearmth">
					<my-list
						propTitle="考勤期间"
						:propValue="form.workPeriodValue"
						mustIcon
						:boldValue="form.workPeriodValue == '请选择' ? false : true"
						:valueColor="form.workPeriodValue == '请选择' ? '#CDCDCD' : '#121F2C'"
						:boder="false"
						isIcon
					></my-list>
				</picker>
				<picker :value="value" @change="seclecTypeFn" class="picker-view" :range="leaveTypeOptions" range-key="label">
					<my-list
						propTitle="请假类别"
						:propValue="form.leaveTypeValue"
						mustIcon
						:boldValue="form.leaveTypeValue == '请选择' ? false : true"
						:valueColor="form.leaveTypeValue == '请选择' ? '#CDCDCD' : '#121F2C'"
						:boder="false"
						isIcon
					></my-list>
				</picker>
				<view v-if="form.leaveTypeValue == '产假'" class="makeLeave">
					<!-- <picker :value="value" @change="childBirthTypeChange" class="picker-view" :range="childBirthTypeOptions">
						<my-list propTitle="分娩方式" :propValue="form.birthLeave.childbirthType" :boder="false"></my-list>
					</picker> -->
					<picker :value="value" @change="birthTypeChange" class="picker-view" :range="birthTypeOptions" range-key="label">
						<my-list propTitle="生育类型" :propValue="form.birthLeave.birthType" :boder="false"></my-list>
					</picker>
				</view>
				<view v-if="form.leaveTypeValue == '病假'" class="makeLeave">
					<!-- <picker :value="value" @change="sickReasonChange" class="picker-view" :range="sickTypeOptions"> -->
					<view class="sick-type-wrap">
						<view class="sick-type-title">病种</view>
						<uni-easyinput type="input" placeholder="请描述病情种类" v-model="form.sickLeave.reason"></uni-easyinput>
					</view>
					<!-- </picker> -->
				</view>
				<view class="error-tips-wrap" v-if="formRuleShow.leaveType">
					<view class="error-tips-sub">
						<span class="iconfont icon-shanchu"></span>
						<view class="error-tips-title">请选择请假类型</view>
					</view>
				</view>
				<!-- +++++++++++++++++++++++++++++++	动态添加time_________________________________ -->
				<my-list propTitle="时间区间" propValue="" mustIcon :boder="false"></my-list>
				<view class="uni-pop-wrap">
					<view v-for="(item, index) in addTiemValue" class="uni-sub">
						<view class="pop-time-sub">
							<view @click="addclickStartTime(item, index)" class="start-time">
								<view class="start-time-title">开始时间</view>
								<view :style="[{ color: item.viewStar == '请选择' ? '#CDCDCD' : '#121F2C' }]">{{ item.viewStar }}</view>
							</view>
							<view @click="addclickEndtTime(item, index)" class="start-time">
								<view class="start-time-title">结束时间</view>
								<view :style="[{ color: item.viewEnd == '请选择' ? '#CDCDCD' : '#121F2C' }]">{{ item.viewEnd }}</view>
							</view>
							<view class="err-tips" v-if="item.timeRule">
								<span class="iconfont icon-shanchu"></span>
								<view class="error-tips-title">结束时间不能小于开始时间</view>
							</view>
						</view>
						<view @click="deleteTime(index)" class="uni-sub-delete" v-if="addTiemValue.length != 1">删除</view>
					</view>
				</view>
				
				<itmister-date-picker ref="pickerst0" @dateConfirm="confirpicker"></itmister-date-picker>
				<itmister-date-picker ref="pickerst" @dateConfirm="confirEndpicker"></itmister-date-picker>
				<!-- +++++++++++++++++++++++++++++++	动态添加time_________________________________ -->
				<view @click="addTime" class="reduce-time">
					添加更多
					<text v-if="addTiemValue.length != 0">...</text>
				</view>

				<my-list propTitle="时长(自动计算)" :propValue="form.duration1 + form.duration2 + '天'" boldValue mustIcon valueColor="#121F2C" :boder="false" isIcon></my-list>
			</view>
		</view>
		<view class="leave-reason-wrap">
			<!-- <view class="wrap-tips">请假事由</view> -->
			<my-list propTitle="请假事由" :boldValue="form.startTime != '请选择'" :boder="false" mustIcon=""></my-list>
			<!-- <view class="example-leave">
				<my-tag :value="item.value" v-for="(item, index) in exampleReason" :key="index" @click="clickExample(item, index)" :activeColor="item.activeColor"></my-tag>
			</view> -->
		</view>
		<view class="reason-textarea">
			<uni-easyinput type="textarea" placeholder="请描述请假事由" v-model="form.reason"></uni-easyinput>
			<view class="err-tips" v-if="formRuleShow.leaveReason">
				<span class="iconfont icon-shanchu"></span>
				<view class="error-tips-title">请输入请假事由</view>
			</view>
		</view>
		<upload @click="clickDowload" @select="select" file_data="1"></upload>

		<view class="filie-list">
			<view v-for="(item, index) in fileValue" :key="index" class="file-sub">
				<view @click="clickDowload(item)">{{ item.name }}</view>
				<view @click="deleteFilebyApi(item)" class="delete">删除</view>
			</view>
		</view>
		<!-- <xp-picker ref="pickerStarttime"  @confirm="confirStartTime" height='25' mode='ymd' :year-range='[new Date().getFullYear(),null]'/></xp-picker> -->
		<!-- <xp-picker ref="pickerEndtime"  @confirm="confirEndTime" height='25' mode='ymd' :year-range='[new Date().getFullYear(),null]'/> -->
		<itmister-date-picker ref="pickerStarttime" @dateConfirm="confirStartTime"></itmister-date-picker>
		<itmister-date-picker ref="pickerEndtime" @dateConfirm="confirEndTime"></itmister-date-picker>
		<view class="confirm-btn" v-if="pageStatus == 0"><my-button width="540" height="88" @click="avice"></my-button></view>
		<view id="dowload"></view>
		<view class="confirm-btn" v-if="pageStatus == 1&&propData.appStatus==-1"><my-button width="540" height="88" @click="adviceChange">确认修改</my-button></view>
		<view class="view-mask" v-show="propData&&propData.appStatus!=-1"></view>
		<!-- 阻止用户点击 -->
	</view>
</template>

<script>
import utils from '../../../common/utils/utils.js';
import service2 from '../../salary/service/salaryService.js';
import service from '../../../common/service/new_file.js';
import apiData from '../../../common/utils/apiData.js';
export default {
	data() {
		return {
			action: 'http://www.example.com/upload',
			appStatusFormChange: '',
			fileValue: [],
			pageStatus: 0, //新建的状态是0，修改的状态是1
			value: [0],
			leaveDays: {
				onVacation: '0',
				vacationUsed: '0' //已用假期
			},
			addTiemValue: [
				{
					viewStar: '请选择',
					modeStar: '',
					viewEnd: '请选择',
					modeEnd: '请选择',
					modeDuring: 0,
					timeRules: false
				}
			],

			worKPeriodOption: [],
			workPeriodValue: 0,
			form: {
				leaveTypeValue: '请选择',
				leaveTypeServiceValue: '',
				leaveShifValue: '请选择',
				leaveShiftStatus: true, //假期类型未选就禁用班次
				leaveShifServiceValue: '',
				workPeriodValue: '请选择',
				workPeriodService: '',
				birthLeave: {
					childbirthType: '请选择',
					birthType: '请选择',
					birthTypeService: ''
				},

				sickLeave: {
					reason: ''
				},
				startTime: '请选择',
				starTimeAfter: '',
				startTimeService: '',
				startTimeStamp: '',
				endTime: '请选择',
				endTimeAfter: '',
				endTimeService: '请选择',
				endTimeStamp: '',
				duration1: 0,
				duration2: 0,
				reason: ''
			}, //假期的表单提交
			formRuleShow: {
				leaveType: false,
				startTime: false,
				endTime: false,
				startAndEndTime: false,
				leaveReason: false
			},
			sickTypeOptions: ['发烧', '感冒', '骨折'],
			childBirthTypeOptions: ['顺产', '剖腹'],
			birthTypeOptions: [
				{
					label: '一胎',
					value: 0
				},
				{
					label: '二胎',
					value: 1
				},
				{
					label: '三胎',
					value: 2
				}
			],
			leaveTypeOptions: [],
			leaveShiftOptions: ['请选择假期类型'],
			choicedIndex: 0,
			fileFormData: null,
			propData: null,
			hasDeletedTime: [], //已被删掉的time
			url: '',
			pk: ''
		};
	},
	methods: {
		clickDowload(item) {
			var query = window.location.origin;
			let url = query + item.url;
			window.open(url);
		},
		deleteFilebyApi(item) {
			let _this = this;
			let pk = item.pk;
			let data = apiData.deleteFile(pk);
			service.common(data, {
				success: function() {
					uni.showToast({
						title: '删除成功',
						icon: 'none'
					});
					_this.getFileList(_this.pk);
				},
				fail: err => {
					uni.showToast({
						title: '请重试',
						icon: 'none'
					});
				}
			});
		},
		select(e) {
			this.fileFormData = e;
			console.log(this.fileFormData);
		},
		getFileList(pk) {
			let _this = this;
			let data = apiData.getFileList(pk);
			service.common(data, {
				success: function(res) {
					let fileData = [];
					res.data.VALUES.forEach(item => {
						fileData.push({
							name: item.filename,
							extname: 'xls',
							url: item.filepath,
							pk: item.pk
						});
					});
					_this.fileValue = fileData;
					// alert(JSON.stringify(res.data))
				},
				fail: function(res) {}
			});
		}, //获取文件列表

		confirmUpload(pk) {
			uni.showLoading({
				title: '上传中'
			});
			const xhr = new XMLHttpRequest();
			const formData = new FormData();
			formData.append('TYPE', 11);
			formData.append('KEY', 'wdhl');
			formData.append('SID', Math.floor(Math.random() * 100));
			//修改
			let billName = 'ZPXQ';
			formData.append('billtype', billName);
			formData.append('SRCSYS', '企业微信');
			formData.append('pk', pk);
			formData.append('creator', '1001A11000000000FEH7');
			formData.append('fileName', this.fileFormData[0].name);
			formData.append('file', this.fileFormData[0]);
			xhr.open('POST', '/service/uploadFileServlet', true);
			xhr.onreadystatechange = function(res) {
				if (res.currentTarget.response != '') {
					if (JSON.parse(res.currentTarget.response).STATUS == 'ERROR') {
						uni.hideLoading();
						alert('上传失败');
					} else {
						uni.hideLoading();
						uni.showToast({
							title: '上传成功',
							icon: 'none',
							duration: 1500
						});
					}
				}
			};
			xhr.send(formData);
		}, //上传文件的http模块
		success(e) {
			console.log(e);
		},
		// +++++++++++++++++修改内容的部分+++++++++++++++++++++
		getLeaveInfor(propItem) {
			function getTimeSTamp(time) {
				let startStamp = new Date(time.split(' ')[0].replace(/-/g, '/')).getTime();
				return startStamp;
			}
			let sumDays = 0;
			let addMoreTimeList = [];
			propItem.timeArr.forEach((item, index) => {
				addMoreTimeList.push({
					viewStar: item.start,
					modeStar: this.getModeEndTime(item.start, 'start'),
					startTimeStamp: getTimeSTamp(item.start),
					dr: '0', //数据删掉之后dr为1
					viewEnd: item.endTime,
					modeEnd: this.getModeEndTime(item.endTime, 'end'),
					endTimeStamp: getTimeSTamp(item.endTime),
					modeDuring: item.leavehours, //要从列表拿下天数
					ts: item.tsbody,
					pk_leave_b: item.pk_leave_b
				});
			});
			this.form.leaveTypeValue = propItem.pk_leavetype.name;
			this.form.tsbody = propItem.timeArr[0].tsbody;
			this.form.pk_leave_b = propItem.timeArr[0].pk_leave_b;

			this.form.workPeriodValue = propItem.pk_period.name;
			this.form.workPeriodService = propItem.pk_period.pk;

			this.form.leaveTypeServiceValue = propItem.pk_leavetype.pk;
			this.form.leaveShifServiceValue = propItem.leaveshift.leaveshift;

			this.form.reason = propItem.leaveremark;
			this.addTiemValue = addMoreTimeList; //绑定动态添加的数据
			this.getDurationSum();
			// this.confirEndTime({
			// 	date: propItem.timeArr[0].endTime.split(' ')[0],
			// 	halfDays: propItem.timeArr[0].endTime.split(' ')[1],
			// 	timeStamp: new Date(propItem.timeArr[0].endTime.split(' ')[0]).getTime()
			// })

			// this.comfirmAddTime()
			// this.confirStartTime()
			// this.confirEndTime()
			// this.comfirmAddTime()
		}, //绑定动态显示
		composeChangeTimeDate(formItem, propData) {
			let formData;
			let formObj = formItem;
			let leavebeginpro; //开始时间的标记
			let leaveendpro; //结束时间的标记
			if (formObj.viewStar.indexOf('上午') != -1) {
				leavebeginpro = '2';
			} else if (formObj.viewStar.indexOf('下午') != -1) {
				leavebeginpro = '3';
			} //上午标记
			if (formObj.viewEnd.indexOf('上午') != -1) {
				leaveendpro = '2';
			} else if (formObj.viewEnd.indexOf('下午') != -1) {
				leaveendpro = '3';
			} //下午标记
			formData = {
				leavebegintime: formObj.modeStar,
				leaveendtime: formObj.modeEnd,
				leavehour: this.CPU_leaveHour([formObj.startTimeStamp, formObj.viewStar], [formObj.endTimeStamp, formObj.viewEnd]),
				leaveremark: this.form.reason,
				leaveshift: this.form.leaveShifServiceValue,
				leaveshiftpro: '3',
				rowno: '10',
				dr: formItem.dr,
				leavebeginpro: leavebeginpro,
				leaveendpro: leaveendpro,
				ts: formItem.ts,
				pk_leave_b: formItem.pk_leave_b,
				pk_leave_h: propData.pk_leave_h
			};
			return formData;
		}, //组合改变的值
		getDurationSum() {
			let sum = 0;
			this.addTiemValue.forEach(item => {
				if (item.startTimeStamp == '' || item.endTimeStamp == '') {
					// console.log(this.CPU_leaveHour([item.startTimeStamp,item.viewStar],[item.endTimeStamp,item.viewEnd]))
					console.log('1');
				} else {
					sum += this.CPU_leaveHour([item.startTimeStamp, item.viewStar], [item.endTimeStamp, item.viewEnd]);
				}
			});
			this.form.duration1 = sum;
		}, //自动计算天数
		CPU_timeRules(start, end) {
			return false;
		}, //判断开始时间是否小于结束时间
		getChangeData() {
			let newFormData = [];
			for (let i = 0; i < this.addTiemValue.length; i++) {
				this.addTiemValue[i].dr = '0';
				newFormData.push(this.composeChangeTimeDate(this.addTiemValue[i], this.propData));
			} //把已删除的时间dr变为1
			for (let i = 0; i < this.hasDeletedTime.length; i++) {
				this.hasDeletedTime[i].dr = '1';
				newFormData.push(this.composeChangeTimeDate(this.hasDeletedTime[i], this.propData));
			} //把已删除的时间dr变为1
			return newFormData;
		}, //获得改变后的时间，把删除的和未删除的分类管理，删除的标记上dr = 1
		adviceChange() {
			if (this.propData.appStatus == -1) {
				let formData = this.getChangeData();
				let head = {
					pk_leave_h: this.propData.pk_leave_h,
					pk_leavetype: this.form.leaveTypeServiceValue,
					pk_org_v: this.propData.pk_org_v.pk,
					pk_period: this.form.workPeriodService,
					ts: this.propData.tshead,
					creator: this.propData.creator.pk,
					billmaker: this.propData.billmaker.pk,
					billno: this.propData.billno,
					vdef2: this.form.birthLeave.birthTypeService,
					vdef3: this.form.sickLeave.reason
				};
				let data = apiData.changeLeaveData(head, formData);
				if (this.CPu_isEnpty()) {
					service.common(data, {
						success: res => {
							uni.showToast({
								title: '提交成功',
								complete() {
									setTimeout(() => {
										uni.navigateTo({
											url: '../../me/approvalRecord'
										});
									}, 1500);
								}
							});
							if (this.fileFormData != null) {
								this.confirmUpload(res.data.VALUES[0].data.hvo.pk_leave_h);
							}
						},
						fail: err => {}
					});
				} else {
					uni.showToast({
						title: '当前存在为空的时间！请删除',
						icon: 'none',
						duration: 2000
					});
				}
			} else {
				uni.showToast({
					title: '当前单据不支持更改',
					icon: 'none',
					duration: 2000
				});
			}
		}, //提交修改后的数据
		//获得动态添加的时间
		// +++++++++++++++++修改内容的部分+++++++++++++++++++++
		// +++++++++++++++++动态添加Select的部分+++++++++++++++++++++
		addclickStartTime(item, index) {
			this.$refs.pickerst0.show();
			this.choicedIndex = index;
		},
		CPU_leaveHour(start, end) {
			//star,和end传数组，数组里面，第一个为时间戳，第二个为视图时间。
			let result = (result = Math.floor(end[0] / 1000 / 60 / 60 / 24) - Math.floor(start[0] / 1000 / 60 / 60 / 24));
			let all = [...start, ...end].filter(item => item == 0 || item == '请选择' || item == '');
			let st = start[1];
			let eT = end[1];
			let duration = 0;
			if (RegExp(/全天/).test(st) && RegExp(/全天/).test(eT)) {
				duration = result + 1;
			}
			if (RegExp(/全天/).test(st) && RegExp(/上午/).test(eT)) {
				duration = result + 0.5;
			}
			if (RegExp(/全天/).test(st) && RegExp(/下午/).test(eT)) {
				duration = result + 1;
			}
			if (RegExp(/上午/).test(st) && RegExp(/全天/).test(eT)) {
				duration = result + 1;
			}
			if (RegExp(/上午/).test(st) && RegExp(/上午/).test(eT)) {
				duration = result + 0.5;
			}
			if (RegExp(/上午/).test(st) && RegExp(/下午/).test(eT)) {
				duration = result + 1;
			}
			if (RegExp(/下午/).test(st) && RegExp(/全天/).test(eT)) {
				duration = result + 0.5;
			}
			if (RegExp(/下午/).test(st) && RegExp(/上午/).test(eT)) {
				duration = result;
			}
			if (RegExp(/下午/).test(st) && RegExp(/下午/).test(eT)) {
				duration = result + 0.5;
			}
			return duration;
		}, //计算两个时间距离的天数，后面逻辑判断半天的情况存在
		addclickEndtTime(item, index) {
			this.choicedIndex = index; //当前点击的时间index
			this.$refs.pickerst.show();
		},
		addTime() {
			this.addTiemValue.push({
				viewStar: '请选择',
				modeStar: '',
				startTimeStamp: 0,
				viewEnd: '请选择',
				modeEnd: '',
				endTimeStamp: 0,
				modeDuring: 0
			});
		}, //添加项
		CPu_isEnpty() {
			let newArr = this.addTiemValue;
			let filterArr = newArr.filter(item => item.viewEnd == '请选择' && item.viewStar == '请选择');
			if (filterArr.length == 0) {
				return true;
			} else {
				return false;
			}
		}, //判断最终数据有没有未填写的
		getModeEndTime(timeHalf, type) {
			let modeTime;
			if (type == 'end') {
				let hours = '13:00:00';
				let hours2 = '23:00:00';
				if (timeHalf.indexOf('上午') != -1) {
					modeTime = timeHalf.split(' ')[0] + ' ' + hours;
				} else if (timeHalf.indexOf('下午') != -1) {
					modeTime = timeHalf.split(' ')[0] + ' ' + hours2;
				}
			} else if (type == 'start') {
				let hours = '01:00:00';
				let hours2 = '13:00:00';
				if (timeHalf.indexOf('上午') != -1) {
					modeTime = timeHalf.split(' ')[0] + ' ' + hours;
				} else if (timeHalf.indexOf('下午') != -1) {								
					modeTime = timeHalf.split(' ')[0] + ' ' + hours2;
				}
			}

			return modeTime;
		}, //重新组合选择出来的时间
		confirpicker(value) {
			if (value.halfDays == 0) {
				uni.showToast({
					icon: 'none',
					title: '请选择班次'
				});
			} else {
				let choicedItem = this.addTiemValue[this.choicedIndex];
				choicedItem.viewStar = value.date + ' ' + value.halfDays;
				choicedItem.timeRule = false;
				choicedItem.startTimeStamp = value.timeStamp;
				choicedItem.modeStar = this.getModeEndTime(value.date + ' ' + value.halfDays, 'start');
				// this.getAddMoreTimeList(this.choicedIndex);
				this.getDurationSum();
				//开始的时间的部分
			}
		},
		//开始时间的点击与确认事件
		confirEndpicker(value) {
			if (value.halfDays == 0) {
				uni.showToast({
					icon: 'none',
					title: '请选择班次'
				});
			} else {
				let choicedItem = this.addTiemValue[this.choicedIndex];
				choicedItem.viewEnd = value.date + ' ' + value.halfDays;
				choicedItem.timeRule = false;
				choicedItem.endTimeStamp = value.timeStamp;
				choicedItem.modeEnd = this.getModeEndTime(value.date + ' ' + value.halfDays, 'end');
				// this.getAddMoreTimeList(this.choicedIndex);
				this.getDurationSum();
				//结束时间的部分
			}
		},
		//结束时间的点击与确认事件
		//添加select项
		deleteTime(index) {
			this.addTiemValue[index].dr = '1'; //删除的项dr变为1
			this.hasDeletedTime.push(this.addTiemValue[index]);
			this.addTiemValue = this.addTiemValue.filter((item, itemIndex) => itemIndex != index);
			this.getDurationSum();
		}, //移除
		showPopTime() {
			this.$refs.pop.open('bottom');
		},

		// +++++++++++++++++动态添加Select的部分+++++++++++++++++++++
		workPeriodSelect(e) {
			let index = e.detail.value;
			this.form.workPeriodValue = this.worKPeriodOption[index].yearmth;
			this.form.workPeriodService = this.worKPeriodOption[index].pk_period_b;
			if (this.form.leaveTypeServiceValue != '') {
				this.getUsedLeaveDay();
			}
		},
		selectLeaveShift() {
			if (this.form.leaveTypeValue == '请选择') {
				uni.showToast({
					icon: 'none',
					title: '请选择请假类型'
				});
			}
		},
		clickMore() {
			uni.navigateTo({
				url: '../../me/approvalRecord'
			});
		},
		getWorkPeriod() {
			let _this = this;
			let data = apiData.setWorkPeriodData();
			service.common(data, {
				success: res => {
					let newArr = [];
					this.worKPeriodOption = res.data.VALUES;
					let month = new Date().getMonth() + 1;
					month = month < 10 ? '0' + month : month;
					let nowTime = new Date().getFullYear() + '-' + month;
					this.worKPeriodOption.forEach((item, index) => {
						if (item.yearmth == nowTime) {
							newArr.push(item);
							this.workPeriodValue = index;
						}
					});
					console.log(newArr);
					this.form.workPeriodValue = newArr[0].yearmth;
					this.form.workPeriodService = newArr[0].pk_period_b;
				}
			});
		},
		seclecTypeFn(e) {
			this.form.leaveTypeValue = this.leaveTypeOptions[e.detail.value].label;
			this.form.leaveTypeServiceValue = this.leaveTypeOptions[e.detail.value].value;
			let head = {
				leavetype: this.form.leaveTypeServiceValue,
				pk_period: this.form.workPeriodService
			};
			this.getUsedLeaveDay(head);
			this.form.birthLeave = {
				childbirthType: '请选择',
				birthType: '请选择'
			};
			this.form.sickLeave = {
				reason: ''
			};
			this.form.leaveShiftStatus = false;
			this.form.leaveShifValue = '请选择';
			this.getAllLeaveShift(this.form.leaveTypeServiceValue);
		},
		leaveShiftTypeFn(e) {
			this.form.leaveShifValue = this.leaveShiftOptions[e.detail.value].label;
			this.form.leaveShifServiceValue = this.leaveTypeOptions[e.detail.value].value;
		},
		birthTypeChange(e) {
			this.form.birthLeave.birthType = this.birthTypeOptions[e.detail.value].label;
			this.form.birthLeave.birthTypeService = this.birthTypeOptions[e.detail.value].value;
		},
		clickStartTime() {
			this.$refs.pickerStarttime.show();
		},
		clickEndtTime() {
			this.$refs.pickerEndtime.show();
		},
		getUsedLeaveDay(leavetype) {
			let head = {
				leavetype: this.form.leaveTypeServiceValue,
				pk_period: this.form.workPeriodService,
				timeyear: this.form.workPeriodValue.split('-')[0]
			};
			let _this = this;
			let data = apiData.getHasLeave(head);
			service.common(data, {
				success: res => {
					if (res.data.VALUES.length == 0 || res.data.VALUES[0].rest == 0) {
						// uni.showToast({
						// 	icon:'none',
						// 	title:'当前剩假期不足,请重新选择'
						// })
						// _this.form.leaveTypeValue='请选择'
						// _this.form.leaveTypeServiceValue = ''
						_this.leaveDays = {
							onVacation: res.data.VALUES.length == 0 ? '0' : res.data.VALUES[0].rested,
							vacationUsed: '0'
						};
					} else {
						_this.leaveDays = {
							onVacation: res.data.VALUES[0].rested,
							vacationUsed: res.data.VALUES[0].rest
						};
					}
				}
			});
		},
		composeTimeDate(formItem) {
			let formData;
			let formObj = formItem;
			let leavebeginpro; //开始时间的标记
			let leaveendpro; //结束时间的标记
			if (formObj.viewStar.indexOf('上午') != -1) {
				leavebeginpro = '2';
			} else if (formObj.viewStar.indexOf('下午') != -1) {
				leavebeginpro = '3';
			} //上午标记
			if (formObj.viewEnd.indexOf('上午') != -1) {
				leaveendpro = '2';
			} else if (formObj.viewEnd.indexOf('下午') != -1) {
				leaveendpro = '3';
			} //下午标记
			formData = {
				leavebegintime: formObj.modeStar,
				leaveendtime: formObj.modeEnd,
				leavehour: this.CPU_leaveHour([formObj.startTimeStamp, formObj.viewStar], [formObj.endTimeStamp, formObj.viewEnd]),
				leaveremark: this.form.reason,
				leaveshift: this.form.leaveShifServiceValue,
				leaveshiftpro: '3',
				rowno: '20',
				leavebeginpro: leavebeginpro,
				leaveendpro: leaveendpro
			};
			return formData;
		}, //组合数据的函数
		getAddTimeFormData() {
			let allTimeDate = [];
			if (this.addTiemValue.length != 0) {
				this.addTiemValue.forEach(item => {
					if (item.endTime == '请选择' && item.startTime == '请选择') {
					} else {
						allTimeDate.push(this.composeTimeDate(item));
					}
				});

				return allTimeDate;
			} else {
				return [];
			}
		}, //遍历取出里面的数组,并把每一项重新组合
		avice() {
			//根据请假的时间记录，取开始时间最小值，重新设定考勤期间，

			let formData = this.getAddTimeFormData();
			let minworkPeriod = new Date(utils.getDateDiff(formData[0].leavebegintime)).getTime();
			let minPeridoArr = [];
			formData.forEach(item => {
				if (new Date(utils.getDateDiff(item.leavebegintime)).getTime() < minworkPeriod) {
					minworkPeriod = new Date(utils.getDateDiff(item.leavebegintime)).getTime();
				}
			});
			let minPeridoMonth = new Date(minworkPeriod).getMonth() + 1; //获取当前时间最小的月份
			let minPeridoYear = new Date(minworkPeriod).getFullYear();
			if (minPeridoMonth < 10) {
				minPeridoMonth = '0' + minPeridoMonth;
			}
			let newPeridoDate = minPeridoYear + '-' + minPeridoMonth;
			// if(new Date(newPeridoDate)<this.form.workPeriodValue){
			// 	uni.showToast({
			// 		icon:"none",
			// 		title:"已重新设定考勤期间"
			// 	})
			// }
			let servicePerido = this.worKPeriodOption.filter(item => item.yearmth == newPeridoDate);
			this.form.workPeriodService = servicePerido[0].pk_period_b;
			this.form.workPeriodValue = servicePerido[0].yearmth;

			//根据请假的时间记录，重新设定考勤期间

			let head = {
				pk_leavetype: this.form.leaveTypeServiceValue,
				pk_period: this.form.workPeriodService,
				vdef2: this.form.birthLeave.birthTypeService,
				vdef3: this.form.sickLeave.reason,
				leaveyear: this.form.workPeriodValue.split('-')[0]
			};
			let data = apiData.setLeaveData(head, formData);

			if (this.CPu_isEnpty()) {
				//当提交的表单有数据为空，未填写的时候，此函数为false,否则为true
				service.common(data, {
					success: res => {
						uni.showToast({
							title: '提交成功',
							success() {
								setTimeout(() => {
									uni.navigateTo({
										url: '../../me/approvalRecord'
									});
								}, 1500);
							}
						});
						if (this.fileFormData != null) {
							this.confirmUpload(res.data.VALUES[0].data.hvo.pk_leave_h);
						}
						//成功了之后上传文件
					},
					fail: err => {}
				});
			} else {
				uni.showToast({
					title: '当前存在为空的时间！请删除',
					icon: 'none',
					duration: 2000
				});
			}
		},

		getAllLeaveType() {
			let _this = this;
			let data = apiData.getLeaveTypeData('leavetype');
			service.common(data, {
				success: function(res) {
					let leaveObj = res.data.VALUES[0];
					let leaveOption = [];
					for (let key in leaveObj) {
						leaveOption.push({
							value: key,
							label: leaveObj[key]
						});
					}
					_this.leaveTypeOptions = leaveOption;
				},
				fail: function(res) {
					// console.log(res);
				}
			});
		},
		getAllLeaveShift(pk_leavetype) {
			let _this = this;
			let data = apiData.getLeaveTypeData('leaveshift', pk_leavetype);
			service.common(data, {
				success: function(res) {
					let leaveObj = res.data.VALUES[0];
					let leaveOption = [];
					for (let key in leaveObj) {
						leaveOption.push({
							value: key,
							label: leaveObj[key]
						});
					}
					_this.leaveShiftOptions = leaveOption;
					console.log(leaveOption, 'leaveOption');
					_this.form.leaveShifValue = leaveOption[0].label;
					_this.form.leaveShifServiceValue = leaveOption[0].value;
				},
				fail: function(res) {
					console.log(res);
				}
			});
		} //获取leaveSHift枚举
	},
	onLoad(options) {
		//为修改页面传过来的值
		this.getAllLeaveType();
		this.leaveTypeOptions = utils.getColorByType('leave').map(item => item.titel);
		if (JSON.stringify(options) != '{}') {
			this.propData = JSON.parse(options.item) ? JSON.parse(options.item) : '';
			this.pageStatus = JSON.parse(options.item) ? 1 : 0;
			this.pk = this.propData.pk_leave_h;
			this.getLeaveInfor(this.propData);
			this.getFileList(this.pk);
			this.getUsedLeaveDay();
		}else{
			this.getWorkPeriod();
		}
	},
	onReady() {
		// this.getUsedLeaveDay()
	},
	watch: {
		'form.reason': function(value) {
			if (this.form.reason == '') {
				this.exampleReason.forEach(el => {
					el.activeColor = true;
				});
			}
		}
	}
};
</script>

<style scoped lang="scss">
.view-mask{
	width: 100vw;
	height: 90vh;
	background: red;
	position: absolute;
	bottom: 0;
	opacity: 0;
}
.filie-list {
	padding: 0 36rpx;
}
.file-sub {
	display: flex;
	justify-content: space-between;
	color: #434343;
	padding: 8rpx 10rpx;
	border-bottom: 1rpx solid #dcdcdc;
	margin-bottom: 5rpx;
}
.delete {
	color: red;
	align-items: center;
	font-size: 26rpx;
}
.upFiles {
	padding: 10rpx 36rpx;
}
.upload {
	display: flex;
	flex-direction: row-reverse;
}

.reduce-time {
	color: #007aff;
	width: 130rpx;
	font-weight: 600;
	margin-left: 30rpx;
	font-size: 26rpx;
}

.empty-tips {
	width: 100%;
	text-align: center;
	padding-top: 100rpx;
	font-size: 28rpx;
	color: #c6c6c6;
}

.uni-pop-wrap {
	width: 100vw;
	overflow: hidden;
	padding-bottom: 16rpx;
}

.uni-sub {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 10rpx 6rpx;
	margin: 16rpx 40rpx;
	border-bottom: 2rpx dotted #e6e6e6;

	.uni-sub-delete {
		color: red;
		padding-right: 30rpx;
		font-size: 28rpx;
	}
}

.start-time {
	margin: 10rpx 0;
}

.err-tips {
	display: flex;
	justify-content: flex-end;
	align-items: center;
	font-size: 26rpx;
	color: red;

	.icon-shanchu {
		font-size: 24rpx;
	}

	.error-tips-title {
		margin-left: 10rpx;
	}
}

.start-time-title {
	display: flex;
	align-items: center;
	margin-right: 50rpx;
	font-size: 30rpx;
}

.pop-time-sub {
	display: flex;
	flex-direction: column;

	.start-time {
		display: flex;
		font-size: 30rpx;
		color: #3b3b3b;
	}
}

.pop-btn {
	margin: 0 auto;
	display: flex;
	justify-content: space-between;
	padding: 20rpx 30rpx;
	border-top: 2rpx solid #e6e6e6;
}

.makeLeave {
	padding: 0 30rpx;
}

.error-tips-wrap {
	display: flex;
	width: 100%;

	.error-tips-sub {
		width: 100%;
		display: flex;
		justify-content: flex-end;
		color: red;
		font-size: 24rpx;

		.error-tips-title {
			margin-left: 10rpx;
		}
	}
}

.leave {
	.check-more-btn {
		padding: 10rpx 30rpx;
		display: flex;
		align-items: center;
		font-size: 35rpx;
		color: #007aff;
		justify-content: flex-end;

		.more-line {
			width: 10rpx;
			height: 40rpx;
			background: #007aff;
			border-radius: 6rpx;
			margin: 0 10rpx;
		}
	}

	.show-days {
		padding: 0 30rpx;
		display: flex;
		justify-content: space-between;

		.days-box1 {
			display: flex;
			flex-direction: column;
			justify-content: center;
			flex: 1;
			height: 190rpx;
			background: linear-gradient(270deg, #46a9ff 0%, #0587fa 100%);
			border-radius: 10px;
			padding-left: 40rpx;
			margin-right: 10rpx;
			color: #ffffff;

			.box-days-num {
				font-size: 56rpx;
			}

			.days-tips {
				font-size: 24rpx;
			}
		}

		.days-box2 {
			display: flex;
			flex-direction: column;
			justify-content: center;
			flex: 1;
			height: 190rpx;
			background: #f7f7f7;
			border-radius: 10px;
			padding-left: 40rpx;
			margin-left: 10rpx;

			.box-days-num {
				font-size: 56rpx;
				color: #000000;
			}

			.days-tips {
				font-size: 24rpx;
				color: #808080;
			}
		}
	}

	.leave-inform-list {
		padding: 0 30rpx;

		.leave-wrap {
			border-bottom: 2rpx solid #e5e5e5;
			padding-bottom: 20rpx;
		}
	}

	.leave-reason-wrap {
		color: #454a5e;
		padding: 0 30rpx;

		.wrap-tips {
			font-weight: 400;
			font-size: 32rpx;
			padding-top: 30rpx;
			padding-bottom: 12rpx;
		}

		.example-leave {
			display: flex;
		}
	}

	.confirm-btn {
		display: flex;
		justify-content: center;
		padding: 50rpx;
	}
}

.reason-textarea {
	padding: 0 28rpx;
}

.sick-type-wrap {
	display: flex;
	align-items: center;

	.sick-type-title {
		margin-right: 10rpx;
		font-size: 32rpx;
		color: #454a5e;
	}
}
</style>
